/* TourColl.java
 * 
 * This is the collection of tours in the application
 * it will be based off a TreeMap because no dupicate
 * names of tours are allowed and this will keep them 
 * in alphabetical order
 * 
 * 
 * 
 * Greg Warner
 * Derek Dupuis
 * Michael Dixey
 * Alex Schwartz
 */

import java.util.*;

public class TourColl extends TreeMap< String, Tour >
   implements CollectionIF<Tour>
{
   public TourColl()
   {
      super();
   }
   
   
   
   //-----------------------------CollectionIF methods-----------------
   
   //adds a tour to the list
   public boolean add( Tour t )
   {
      if ( ! this.containsKey( t.name( ) ) )
      {
         this.put(t.name(), t);
         return true;
      }
      else
      {
         System.err.printf( "Tour of %s already exists!\n",
                           t.name() );
         return false;
      }
   }
   
   //returns true if tour is in the list already
   public boolean find( String s )
   {
      return this.containsKey( s );
   }
   
   public Tour get( String s )
   {
      return super.get( s );
   }
   
   //returns a string representation of the tour
   public String toString()
   {
      String s = "TOURS:\n";
      
      Set    t = this.keySet( );
      
      
      Iterator iter = t.iterator();
      
      while( iter.hasNext() )
         s = s + this.get( iter.next() ).toString() + '\n';
      
      return s;
   }
}